/* ============================================================
 * Part of 'Autostop' project
 * Under GPL license - http://www.gnu.org/licenses/gpl.html
 * (c) 2006 - Autostop team
 */

///@file guidriverwindow.h Declaration of gui driver's main window

#include <QMainWindow>
#include <QImage>
#include <QList>
#include <QVector>

#include "analyzer.h"

#include "ui_guidriverwindow.h"


/// Driver's main window implementation
class GuiDriverWindow : public QMainWindow, protected Ui::GuiDriverWindow
{
	Q_OBJECT
public:	

	GuiDriverWindow();							///< Constrcutor

	void setPath( const QString& path );		///< Sets sequence path
	
protected slots:
	
	void on_startButton_clicked();				///< 'start' button handler
	void on_selectDirButton_clicked();			///< '...' button handler
	void on_positionSlider_sliderMoved( int pos ); ///< slider move handler
	void on_listObjects_itemActivated( QListWidgetItem* pitem );	///< object list activation handle

private:
	
	void loadSequence( const QString& path );	///< Loads sequence fro mfiles in _path
	void loadMarkers( const QString& path ); 	///< Loads distance msrkers
	void processSequence();						///< Processes sequence

	void populateObjectList( pprocess_t pprocess ); ///< Populates object list
	
	void storePath();							///< stores path in persistent sotrage
	void restorePath();							///< restores path from persistent sotrage

	void startLengthyProcess( const QString name, int iterations );	///< Starts lengthy process
	void indicateIteration( int iteration );	///< Indicates of iteration of lengthy process
	void endLengthyProcess();					///< Ends lengthy process

	/// converts image from qt to analyzer format
	static pimage_t imageFromQt( const QImage& image );
	static QImage imageToQt( const pimage_t pimage );
	/// converts marker image into its visual representation
	static QImage markerToQtImage( const pimage_t pmarker );
	static QVector<QRgb> _grayscale;			///< Grayscale color table. Lazy initialized when first needed
	static QVector<QColor> _basicColors;		///< basic group colors. LAzy initiaslzed when firs needed

	/// Converts segmented image into QImage, paints groups
	static QImage paintSegmentedAndGroups( pprocess_t pprocess );

	/// Creates input with painted groups and objects
	QImage paintOutput( pprocess_t pprocess, const QImage& input );

	void showObject( const object_t& object );	///< Paints object's points on output frame

	
	QString _path;								///< Sequence path
	QVector< QImage > _sequence;				///< Sequence data - input
	QVector< QImage > _output;					///< Sequence data - output
	QVector< QImage > _backgrounds;				///< Extracted backgrounds
	QVector< QImage > _segmented;				///< Extracted backgrounds
	QVector< object_t > _objects;				///< Objects at the end ofthe sequence
	QImage _markersImage;						///< Visual representation of markers
	pimage_t _pmarkers;							///< distance markers
};

// eof 

